﻿GO

if exists (select * from sysobjects where id = object_id(N'[sproc_CO_SO_HA_TANG_GetCount]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_CO_SO_HA_TANG_GetCount]
GO

/* Procedure sproc_CO_SO_HA_TANG_GetCount*/
CREATE PROCEDURE sproc_CO_SO_HA_TANG_GetCount
AS
SELECT
	COUNT(*)
FROM
	[CO_SO_HA_TANG]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_CO_SO_HA_TANG_Get]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_CO_SO_HA_TANG_Get]
GO

/* Procedure sproc_CO_SO_HA_TANG_Get*/
CREATE PROCEDURE sproc_CO_SO_HA_TANG_Get
AS
SELECT
	--[MA_HO_SO],
	--[DONG_HO_DIEN],
	--[CAP_TREO],
	--[CAP_NGAM],
	--[DONG_HO_NUOC],
	--[AP_LUC_NUOC],
	--[CHAT_LUONG_NUOC],
	--[TIENG_ON],
	--[KHOI_BUI],
	--[TINH_TRANG_NGAP],
	--[HE_THONG_CHIEU_SANG],
	--[CHOT_BAO_VE],
	--[AN_NINH],
	--[GAN_CO_SO_GIAO_DUC],
	--[GAN_CO_SO_Y_TE],
	--[GAN_CHO_TRUNG_TAM],
	--[GAN_CO_SO_GIAI_TRI],
	--[GAN_DICH_VU_CONG_CONG],
	--[GAN_THONG_TIN_LIEN_LAC]

*
FROM
	[CO_SO_HA_TANG]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_CO_SO_HA_TANG_GetByMA_HO_SO]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_CO_SO_HA_TANG_GetByMA_HO_SO]
GO

/* Procedure sproc_CO_SO_HA_TANG_GetByMA_HO_SO*/
CREATE PROCEDURE sproc_CO_SO_HA_TANG_GetByMA_HO_SO
@MA_HO_SO bigint
AS
SELECT
	--[MA_HO_SO],
	--[DONG_HO_DIEN],
	--[CAP_TREO],
	--[CAP_NGAM],
	--[DONG_HO_NUOC],
	--[AP_LUC_NUOC],
	--[CHAT_LUONG_NUOC],
	--[TIENG_ON],
	--[KHOI_BUI],
	--[TINH_TRANG_NGAP],
	--[HE_THONG_CHIEU_SANG],
	--[CHOT_BAO_VE],
	--[AN_NINH],
	--[GAN_CO_SO_GIAO_DUC],
	--[GAN_CO_SO_Y_TE],
	--[GAN_CHO_TRUNG_TAM],
	--[GAN_CO_SO_GIAI_TRI],
	--[GAN_DICH_VU_CONG_CONG],
	--[GAN_THONG_TIN_LIEN_LAC]

*
FROM
	[CO_SO_HA_TANG]
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO



if exists (select * from sysobjects where id = object_id(N'[sproc_CO_SO_HA_TANG_GetPaged]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_CO_SO_HA_TANG_GetPaged]
GO

/* Procedure sproc_CO_SO_HA_TANG_GetPaged*/
CREATE PROCEDURE sproc_CO_SO_HA_TANG_GetPaged
	@RecPerPage INT,
	@PageIndex INT
AS

DECLARE @FirstRec INT
DECLARE @LastRec INT

SET @FirstRec = (@PageIndex - 1)*@RecPerPage + 1
SET @LastRec = @PageIndex *@RecPerPage 

-- create temp table to paging
CREATE TABLE #tmp_paging_index
(
	recID		INT IDENTITY(1,1) NOT NULL,
	messageID	bigint
)

-- insert temp records
INSERT INTO #tmp_paging_index(messageID)
SELECT [MA_HO_SO]
FROM [CO_SO_HA_TANG]


-- query out
SELECT *
FROM [CO_SO_HA_TANG]
WHERE [MA_HO_SO]
IN (
	SELECT messageID 
	FROM #tmp_paging_index 
	WHERE recID >= @FirstRec AND recID <= @LastRec
)
DROP TABLE #tmp_paging_index

GO



if exists (select * from sysobjects where id = object_id(N'[sproc_CO_SO_HA_TANG_Add]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_CO_SO_HA_TANG_Add]
GO

/* Procedure sproc_CO_SO_HA_TANG_Add*/
CREATE PROCEDURE sproc_CO_SO_HA_TANG_Add
	@MA_HO_SO bigint
	,@DONG_HO_DIEN int
	,@CAP_TREO int
	,@CAP_NGAM int
	,@DONG_HO_NUOC int
	,@AP_LUC_NUOC int
	,@CHAT_LUONG_NUOC int
	,@TIENG_ON int
	,@KHOI_BUI int
	,@TINH_TRANG_NGAP int
	,@HE_THONG_CHIEU_SANG int
	,@CHOT_BAO_VE int
	,@AN_NINH int
	,@GAN_CO_SO_GIAO_DUC int
	,@GAN_CO_SO_Y_TE int
	,@GAN_CHO_TRUNG_TAM int
	,@GAN_CO_SO_GIAI_TRI int
	,@GAN_DICH_VU_CONG_CONG int
	,@GAN_THONG_TIN_LIEN_LAC int

AS

	INSERT INTO [CO_SO_HA_TANG]
	(
		[MA_HO_SO],
		[DONG_HO_DIEN],
		[CAP_TREO],
		[CAP_NGAM],
		[DONG_HO_NUOC],
		[AP_LUC_NUOC],
		[CHAT_LUONG_NUOC],
		[TIENG_ON],
		[KHOI_BUI],
		[TINH_TRANG_NGAP],
		[HE_THONG_CHIEU_SANG],
		[CHOT_BAO_VE],
		[AN_NINH],
		[GAN_CO_SO_GIAO_DUC],
		[GAN_CO_SO_Y_TE],
		[GAN_CHO_TRUNG_TAM],
		[GAN_CO_SO_GIAI_TRI],
		[GAN_DICH_VU_CONG_CONG],
		[GAN_THONG_TIN_LIEN_LAC]
	)
	VALUES
	(
		@MA_HO_SO,
		@DONG_HO_DIEN,
		@CAP_TREO,
		@CAP_NGAM,
		@DONG_HO_NUOC,
		@AP_LUC_NUOC,
		@CHAT_LUONG_NUOC,
		@TIENG_ON,
		@KHOI_BUI,
		@TINH_TRANG_NGAP,
		@HE_THONG_CHIEU_SANG,
		@CHOT_BAO_VE,
		@AN_NINH,
		@GAN_CO_SO_GIAO_DUC,
		@GAN_CO_SO_Y_TE,
		@GAN_CHO_TRUNG_TAM,
		@GAN_CO_SO_GIAI_TRI,
		@GAN_DICH_VU_CONG_CONG,
		@GAN_THONG_TIN_LIEN_LAC
	)
GO
if exists (select * from sysobjects where id = object_id(N'[sproc_CO_SO_HA_TANG_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_CO_SO_HA_TANG_Update]
GO

/* Procedure sproc_CO_SO_HA_TANG_Update*/
CREATE PROCEDURE sproc_CO_SO_HA_TANG_Update
	@DONG_HO_DIEN int,
	@CAP_TREO int,
	@CAP_NGAM int,
	@DONG_HO_NUOC int,
	@AP_LUC_NUOC int,
	@CHAT_LUONG_NUOC int,
	@TIENG_ON int,
	@KHOI_BUI int,
	@TINH_TRANG_NGAP int,
	@HE_THONG_CHIEU_SANG int,
	@CHOT_BAO_VE int,
	@AN_NINH int,
	@GAN_CO_SO_GIAO_DUC int,
	@GAN_CO_SO_Y_TE int,
	@GAN_CHO_TRUNG_TAM int,
	@GAN_CO_SO_GIAI_TRI int,
	@GAN_DICH_VU_CONG_CONG int,
	@GAN_THONG_TIN_LIEN_LAC int,
	@MA_HO_SO bigint

AS
UPDATE [CO_SO_HA_TANG]
SET
	[DONG_HO_DIEN] = @DONG_HO_DIEN,
	[CAP_TREO] = @CAP_TREO,
	[CAP_NGAM] = @CAP_NGAM,
	[DONG_HO_NUOC] = @DONG_HO_NUOC,
	[AP_LUC_NUOC] = @AP_LUC_NUOC,
	[CHAT_LUONG_NUOC] = @CHAT_LUONG_NUOC,
	[TIENG_ON] = @TIENG_ON,
	[KHOI_BUI] = @KHOI_BUI,
	[TINH_TRANG_NGAP] = @TINH_TRANG_NGAP,
	[HE_THONG_CHIEU_SANG] = @HE_THONG_CHIEU_SANG,
	[CHOT_BAO_VE] = @CHOT_BAO_VE,
	[AN_NINH] = @AN_NINH,
	[GAN_CO_SO_GIAO_DUC] = @GAN_CO_SO_GIAO_DUC,
	[GAN_CO_SO_Y_TE] = @GAN_CO_SO_Y_TE,
	[GAN_CHO_TRUNG_TAM] = @GAN_CHO_TRUNG_TAM,
	[GAN_CO_SO_GIAI_TRI] = @GAN_CO_SO_GIAI_TRI,
	[GAN_DICH_VU_CONG_CONG] = @GAN_DICH_VU_CONG_CONG,
	[GAN_THONG_TIN_LIEN_LAC] = @GAN_THONG_TIN_LIEN_LAC
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO

if exists (select * from sysobjects where id = object_id(N'[sproc_CO_SO_HA_TANG_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_CO_SO_HA_TANG_Delete]
GO

/* Procedure sproc_CO_SO_HA_TANG_Delete*/
CREATE PROCEDURE sproc_CO_SO_HA_TANG_Delete
	@MA_HO_SO bigint
AS
DELETE
FROM
	[CO_SO_HA_TANG]
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO

if exists (select * from sysobjects where id = object_id(N'[sproc_CONG_TRINH_XAY_DUNG_GetCount]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_CONG_TRINH_XAY_DUNG_GetCount]
GO

/* Procedure sproc_CONG_TRINH_XAY_DUNG_GetCount*/
CREATE PROCEDURE sproc_CONG_TRINH_XAY_DUNG_GetCount
AS
SELECT
	COUNT(*)
FROM
	[CONG_TRINH_XAY_DUNG]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_CONG_TRINH_XAY_DUNG_Get]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_CONG_TRINH_XAY_DUNG_Get]
GO

/* Procedure sproc_CONG_TRINH_XAY_DUNG_Get*/
CREATE PROCEDURE sproc_CONG_TRINH_XAY_DUNG_Get
AS
SELECT
	--[MA_HO_SO],
	--[LOAI_NHA],
	--[NOI_DUNG_LOAI_NHA],
	--[LOAI_CAP_NHA],
	--[HUONG_NHA],
	--[GIAY_PHEP_XAY_DUNG],
	--[DIEN_TICH_XD_CONG_NHAN],
	--[DIEN_TICH_XD_KHONG_CONG_NHAN],
	--[NAM_XAY_DUNG],
	--[SO_NAM_SU_DUNG],
	--[DON_GIA_XAY_DUNG],
	--[TUOI_DOI_KINH_TE],
	--[GIA_TRI_CONG_TRINH],
	--[SO_LAN_SUA_CHUA]

*
FROM
	[CONG_TRINH_XAY_DUNG]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_CONG_TRINH_XAY_DUNG_GetByMA_HO_SO]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_CONG_TRINH_XAY_DUNG_GetByMA_HO_SO]
GO

/* Procedure sproc_CONG_TRINH_XAY_DUNG_GetByMA_HO_SO*/
CREATE PROCEDURE sproc_CONG_TRINH_XAY_DUNG_GetByMA_HO_SO
@MA_HO_SO bigint
AS
SELECT
	--[MA_HO_SO],
	--[LOAI_NHA],
	--[NOI_DUNG_LOAI_NHA],
	--[LOAI_CAP_NHA],
	--[HUONG_NHA],
	--[GIAY_PHEP_XAY_DUNG],
	--[DIEN_TICH_XD_CONG_NHAN],
	--[DIEN_TICH_XD_KHONG_CONG_NHAN],
	--[NAM_XAY_DUNG],
	--[SO_NAM_SU_DUNG],
	--[DON_GIA_XAY_DUNG],
	--[TUOI_DOI_KINH_TE],
	--[GIA_TRI_CONG_TRINH],
	--[SO_LAN_SUA_CHUA]

*
FROM
	[CONG_TRINH_XAY_DUNG]
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO



if exists (select * from sysobjects where id = object_id(N'[sproc_CONG_TRINH_XAY_DUNG_GetPaged]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_CONG_TRINH_XAY_DUNG_GetPaged]
GO

/* Procedure sproc_CONG_TRINH_XAY_DUNG_GetPaged*/
CREATE PROCEDURE sproc_CONG_TRINH_XAY_DUNG_GetPaged
	@RecPerPage INT,
	@PageIndex INT
AS

DECLARE @FirstRec INT
DECLARE @LastRec INT

SET @FirstRec = (@PageIndex - 1)*@RecPerPage + 1
SET @LastRec = @PageIndex *@RecPerPage 

-- create temp table to paging
CREATE TABLE #tmp_paging_index
(
	recID		INT IDENTITY(1,1) NOT NULL,
	messageID	bigint
)

-- insert temp records
INSERT INTO #tmp_paging_index(messageID)
SELECT [MA_HO_SO]
FROM [CONG_TRINH_XAY_DUNG]


-- query out
SELECT *
FROM [CONG_TRINH_XAY_DUNG]
WHERE [MA_HO_SO]
IN (
	SELECT messageID 
	FROM #tmp_paging_index 
	WHERE recID >= @FirstRec AND recID <= @LastRec
)
DROP TABLE #tmp_paging_index

GO



if exists (select * from sysobjects where id = object_id(N'[sproc_CONG_TRINH_XAY_DUNG_Add]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_CONG_TRINH_XAY_DUNG_Add]
GO

/* Procedure sproc_CONG_TRINH_XAY_DUNG_Add*/
CREATE PROCEDURE sproc_CONG_TRINH_XAY_DUNG_Add
	@MA_HO_SO bigint
	,@LOAI_NHA bigint
	,@NOI_DUNG_LOAI_NHA NVARCHAR(50)
	,@LOAI_CAP_NHA bigint
	,@HUONG_NHA bigint
	,@GIAY_PHEP_XAY_DUNG char(1)
	,@DIEN_TICH_XD_CONG_NHAN float(8)
	,@DIEN_TICH_XD_KHONG_CONG_NHAN float(8)
	,@NAM_XAY_DUNG datetime
	,@SO_NAM_SU_DUNG float(8)
	,@DON_GIA_XAY_DUNG float(8)
	,@TUOI_DOI_KINH_TE float(8)
	,@GIA_TRI_CONG_TRINH float(8)
	,@SO_LAN_SUA_CHUA int

AS

	INSERT INTO [CONG_TRINH_XAY_DUNG]
	(
		[MA_HO_SO],
		[LOAI_NHA],
		[NOI_DUNG_LOAI_NHA],
		[LOAI_CAP_NHA],
		[HUONG_NHA],
		[GIAY_PHEP_XAY_DUNG],
		[DIEN_TICH_XD_CONG_NHAN],
		[DIEN_TICH_XD_KHONG_CONG_NHAN],
		[NAM_XAY_DUNG],
		[SO_NAM_SU_DUNG],
		[DON_GIA_XAY_DUNG],
		[TUOI_DOI_KINH_TE],
		[GIA_TRI_CONG_TRINH],
		[SO_LAN_SUA_CHUA]
	)
	VALUES
	(
		@MA_HO_SO,
		@LOAI_NHA,
		@NOI_DUNG_LOAI_NHA,
		@LOAI_CAP_NHA,
		@HUONG_NHA,
		@GIAY_PHEP_XAY_DUNG,
		@DIEN_TICH_XD_CONG_NHAN,
		@DIEN_TICH_XD_KHONG_CONG_NHAN,
		@NAM_XAY_DUNG,
		@SO_NAM_SU_DUNG,
		@DON_GIA_XAY_DUNG,
		@TUOI_DOI_KINH_TE,
		@GIA_TRI_CONG_TRINH,
		@SO_LAN_SUA_CHUA
	)
GO
if exists (select * from sysobjects where id = object_id(N'[sproc_CONG_TRINH_XAY_DUNG_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_CONG_TRINH_XAY_DUNG_Update]
GO

/* Procedure sproc_CONG_TRINH_XAY_DUNG_Update*/
CREATE PROCEDURE sproc_CONG_TRINH_XAY_DUNG_Update
	@LOAI_NHA bigint,
	@NOI_DUNG_LOAI_NHA NVARCHAR(50),
	@LOAI_CAP_NHA bigint,
	@HUONG_NHA bigint,
	@GIAY_PHEP_XAY_DUNG char(1),
	@DIEN_TICH_XD_CONG_NHAN float(8),
	@DIEN_TICH_XD_KHONG_CONG_NHAN float(8),
	@NAM_XAY_DUNG datetime,
	@SO_NAM_SU_DUNG float(8),
	@DON_GIA_XAY_DUNG float(8),
	@TUOI_DOI_KINH_TE float(8),
	@GIA_TRI_CONG_TRINH float(8),
	@SO_LAN_SUA_CHUA int,
	@MA_HO_SO bigint

AS
UPDATE [CONG_TRINH_XAY_DUNG]
SET
	[LOAI_NHA] = @LOAI_NHA,
	[NOI_DUNG_LOAI_NHA] = @NOI_DUNG_LOAI_NHA,
	[LOAI_CAP_NHA] = @LOAI_CAP_NHA,
	[HUONG_NHA] = @HUONG_NHA,
	[GIAY_PHEP_XAY_DUNG] = @GIAY_PHEP_XAY_DUNG,
	[DIEN_TICH_XD_CONG_NHAN] = @DIEN_TICH_XD_CONG_NHAN,
	[DIEN_TICH_XD_KHONG_CONG_NHAN] = @DIEN_TICH_XD_KHONG_CONG_NHAN,
	[NAM_XAY_DUNG] = @NAM_XAY_DUNG,
	[SO_NAM_SU_DUNG] = @SO_NAM_SU_DUNG,
	[DON_GIA_XAY_DUNG] = @DON_GIA_XAY_DUNG,
	[TUOI_DOI_KINH_TE] = @TUOI_DOI_KINH_TE,
	[GIA_TRI_CONG_TRINH] = @GIA_TRI_CONG_TRINH,
	[SO_LAN_SUA_CHUA] = @SO_LAN_SUA_CHUA
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO

if exists (select * from sysobjects where id = object_id(N'[sproc_CONG_TRINH_XAY_DUNG_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_CONG_TRINH_XAY_DUNG_Delete]
GO

/* Procedure sproc_CONG_TRINH_XAY_DUNG_Delete*/
CREATE PROCEDURE sproc_CONG_TRINH_XAY_DUNG_Delete
	@MA_HO_SO bigint
AS
DELETE
FROM
	[CONG_TRINH_XAY_DUNG]
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO

if exists (select * from sysobjects where id = object_id(N'[sproc_DUONG_KHAO_SAT_GetCount]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_DUONG_KHAO_SAT_GetCount]
GO

/* Procedure sproc_DUONG_KHAO_SAT_GetCount*/
CREATE PROCEDURE sproc_DUONG_KHAO_SAT_GetCount
AS
SELECT
	COUNT(*)
FROM
	[DUONG_KHAO_SAT]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_DUONG_KHAO_SAT_Get]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_DUONG_KHAO_SAT_Get]
GO

/* Procedure sproc_DUONG_KHAO_SAT_Get*/
CREATE PROCEDURE sproc_DUONG_KHAO_SAT_Get
AS
SELECT
	--[MA_DKS],
	--[QUAN],
	--[PHUONG],
	--[DUONG],
	--[DOAN_DUONG],
	--[NGAY_KHOI_TAO],
	--[ACTIVE_FLAG]

*
FROM
	[DUONG_KHAO_SAT]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_DUONG_KHAO_SAT_GetByMA_DKS]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_DUONG_KHAO_SAT_GetByMA_DKS]
GO

/* Procedure sproc_DUONG_KHAO_SAT_GetByMA_DKS*/
CREATE PROCEDURE sproc_DUONG_KHAO_SAT_GetByMA_DKS
@MA_DKS bigint
AS
SELECT
	--[MA_DKS],
	--[QUAN],
	--[PHUONG],
	--[DUONG],
	--[DOAN_DUONG],
	--[NGAY_KHOI_TAO],
	--[ACTIVE_FLAG]

*
FROM
	[DUONG_KHAO_SAT]
WHERE
	[MA_DKS] = @MA_DKS
GO



if exists (select * from sysobjects where id = object_id(N'[sproc_DUONG_KHAO_SAT_GetPaged]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_DUONG_KHAO_SAT_GetPaged]
GO

/* Procedure sproc_DUONG_KHAO_SAT_GetPaged*/
CREATE PROCEDURE sproc_DUONG_KHAO_SAT_GetPaged
	@RecPerPage INT,
	@PageIndex INT
AS

DECLARE @FirstRec INT
DECLARE @LastRec INT

SET @FirstRec = (@PageIndex - 1)*@RecPerPage + 1
SET @LastRec = @PageIndex *@RecPerPage 

-- create temp table to paging
CREATE TABLE #tmp_paging_index
(
	recID		INT IDENTITY(1,1) NOT NULL,
	messageID	bigint
)

-- insert temp records
INSERT INTO #tmp_paging_index(messageID)
SELECT [MA_DKS]
FROM [DUONG_KHAO_SAT]


-- query out
SELECT *
FROM [DUONG_KHAO_SAT]
WHERE [MA_DKS]
IN (
	SELECT messageID 
	FROM #tmp_paging_index 
	WHERE recID >= @FirstRec AND recID <= @LastRec
)
DROP TABLE #tmp_paging_index

GO



if exists (select * from sysobjects where id = object_id(N'[sproc_DUONG_KHAO_SAT_Add]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_DUONG_KHAO_SAT_Add]
GO

/* Procedure sproc_DUONG_KHAO_SAT_Add*/
CREATE PROCEDURE sproc_DUONG_KHAO_SAT_Add
	@MA_DKS bigint OUTPUT
	,@QUAN bigint
	,@PHUONG bigint
	,@DUONG NVARCHAR(50)
	,@DOAN_DUONG NVARCHAR(50)
	,@NGAY_KHOI_TAO datetime
	,@ACTIVE_FLAG char(1)

AS

	INSERT INTO [DUONG_KHAO_SAT]
	(
		[QUAN],
		[PHUONG],
		[DUONG],
		[DOAN_DUONG],
		[NGAY_KHOI_TAO],
		[ACTIVE_FLAG]
	)
	VALUES
	(
		@QUAN,
		@PHUONG,
		@DUONG,
		@DOAN_DUONG,
		@NGAY_KHOI_TAO,
		@ACTIVE_FLAG
	)
	SELECT
		@MA_DKS = @@Identity

GO
if exists (select * from sysobjects where id = object_id(N'[sproc_DUONG_KHAO_SAT_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_DUONG_KHAO_SAT_Update]
GO

/* Procedure sproc_DUONG_KHAO_SAT_Update*/
CREATE PROCEDURE sproc_DUONG_KHAO_SAT_Update
	@QUAN bigint,
	@PHUONG bigint,
	@DUONG NVARCHAR(50),
	@DOAN_DUONG NVARCHAR(50),
	@NGAY_KHOI_TAO datetime,
	@ACTIVE_FLAG char(1),
	@MA_DKS bigint

AS
UPDATE [DUONG_KHAO_SAT]
SET
	[QUAN] = @QUAN,
	[PHUONG] = @PHUONG,
	[DUONG] = @DUONG,
	[DOAN_DUONG] = @DOAN_DUONG,
	[NGAY_KHOI_TAO] = @NGAY_KHOI_TAO,
	[ACTIVE_FLAG] = @ACTIVE_FLAG
WHERE
	[MA_DKS] = @MA_DKS
GO

if exists (select * from sysobjects where id = object_id(N'[sproc_DUONG_KHAO_SAT_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_DUONG_KHAO_SAT_Delete]
GO

/* Procedure sproc_DUONG_KHAO_SAT_Delete*/
CREATE PROCEDURE sproc_DUONG_KHAO_SAT_Delete
	@MA_DKS bigint
AS
DELETE
FROM
	[DUONG_KHAO_SAT]
WHERE
	[MA_DKS] = @MA_DKS
GO

if exists (select * from sysobjects where id = object_id(N'[sproc_GIA_THAM_DINH_GetCount]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_GIA_THAM_DINH_GetCount]
GO

/* Procedure sproc_GIA_THAM_DINH_GetCount*/
CREATE PROCEDURE sproc_GIA_THAM_DINH_GetCount
AS
SELECT
	COUNT(*)
FROM
	[GIA_THAM_DINH]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_GIA_THAM_DINH_Get]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_GIA_THAM_DINH_Get]
GO

/* Procedure sproc_GIA_THAM_DINH_Get*/
CREATE PROCEDURE sproc_GIA_THAM_DINH_Get
AS
SELECT
	--[MA_HO_SO],
	--[GIA_GIAO_DICH_TRIEU_DONG],
	--[GIA_GIAO_DICH_CAY_VANG],
	--[THOI_DIEM_GIAO_DICH],
	--[LOAI_THANH_TOAN],
	--[NOI_DUNG_THANH_TOAN]

*
FROM
	[GIA_THAM_DINH]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_GIA_THAM_DINH_GetByMA_HO_SO]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_GIA_THAM_DINH_GetByMA_HO_SO]
GO

/* Procedure sproc_GIA_THAM_DINH_GetByMA_HO_SO*/
CREATE PROCEDURE sproc_GIA_THAM_DINH_GetByMA_HO_SO
@MA_HO_SO bigint
AS
SELECT
	--[MA_HO_SO],
	--[GIA_GIAO_DICH_TRIEU_DONG],
	--[GIA_GIAO_DICH_CAY_VANG],
	--[THOI_DIEM_GIAO_DICH],
	--[LOAI_THANH_TOAN],
	--[NOI_DUNG_THANH_TOAN]

*
FROM
	[GIA_THAM_DINH]
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO



if exists (select * from sysobjects where id = object_id(N'[sproc_GIA_THAM_DINH_GetPaged]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_GIA_THAM_DINH_GetPaged]
GO

/* Procedure sproc_GIA_THAM_DINH_GetPaged*/
CREATE PROCEDURE sproc_GIA_THAM_DINH_GetPaged
	@RecPerPage INT,
	@PageIndex INT
AS

DECLARE @FirstRec INT
DECLARE @LastRec INT

SET @FirstRec = (@PageIndex - 1)*@RecPerPage + 1
SET @LastRec = @PageIndex *@RecPerPage 

-- create temp table to paging
CREATE TABLE #tmp_paging_index
(
	recID		INT IDENTITY(1,1) NOT NULL,
	messageID	bigint
)

-- insert temp records
INSERT INTO #tmp_paging_index(messageID)
SELECT [MA_HO_SO]
FROM [GIA_THAM_DINH]


-- query out
SELECT *
FROM [GIA_THAM_DINH]
WHERE [MA_HO_SO]
IN (
	SELECT messageID 
	FROM #tmp_paging_index 
	WHERE recID >= @FirstRec AND recID <= @LastRec
)
DROP TABLE #tmp_paging_index

GO



if exists (select * from sysobjects where id = object_id(N'[sproc_GIA_THAM_DINH_Add]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_GIA_THAM_DINH_Add]
GO

/* Procedure sproc_GIA_THAM_DINH_Add*/
CREATE PROCEDURE sproc_GIA_THAM_DINH_Add
	@MA_HO_SO bigint
	,@GIA_GIAO_DICH_TRIEU_DONG float(8)
	,@GIA_GIAO_DICH_CAY_VANG float(8)
	,@THOI_DIEM_GIAO_DICH datetime
	,@LOAI_THANH_TOAN bigint
	,@NOI_DUNG_THANH_TOAN NVARCHAR(50)

AS

	INSERT INTO [GIA_THAM_DINH]
	(
		[MA_HO_SO],
		[GIA_GIAO_DICH_TRIEU_DONG],
		[GIA_GIAO_DICH_CAY_VANG],
		[THOI_DIEM_GIAO_DICH],
		[LOAI_THANH_TOAN],
		[NOI_DUNG_THANH_TOAN]
	)
	VALUES
	(
		@MA_HO_SO,
		@GIA_GIAO_DICH_TRIEU_DONG,
		@GIA_GIAO_DICH_CAY_VANG,
		@THOI_DIEM_GIAO_DICH,
		@LOAI_THANH_TOAN,
		@NOI_DUNG_THANH_TOAN
	)
GO
if exists (select * from sysobjects where id = object_id(N'[sproc_GIA_THAM_DINH_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_GIA_THAM_DINH_Update]
GO

/* Procedure sproc_GIA_THAM_DINH_Update*/
CREATE PROCEDURE sproc_GIA_THAM_DINH_Update
	@GIA_GIAO_DICH_TRIEU_DONG float(8),
	@GIA_GIAO_DICH_CAY_VANG float(8),
	@THOI_DIEM_GIAO_DICH datetime,
	@LOAI_THANH_TOAN bigint,
	@NOI_DUNG_THANH_TOAN NVARCHAR(50),
	@MA_HO_SO bigint

AS
UPDATE [GIA_THAM_DINH]
SET
	[GIA_GIAO_DICH_TRIEU_DONG] = @GIA_GIAO_DICH_TRIEU_DONG,
	[GIA_GIAO_DICH_CAY_VANG] = @GIA_GIAO_DICH_CAY_VANG,
	[THOI_DIEM_GIAO_DICH] = @THOI_DIEM_GIAO_DICH,
	[LOAI_THANH_TOAN] = @LOAI_THANH_TOAN,
	[NOI_DUNG_THANH_TOAN] = @NOI_DUNG_THANH_TOAN
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO

if exists (select * from sysobjects where id = object_id(N'[sproc_GIA_THAM_DINH_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_GIA_THAM_DINH_Delete]
GO

/* Procedure sproc_GIA_THAM_DINH_Delete*/
CREATE PROCEDURE sproc_GIA_THAM_DINH_Delete
	@MA_HO_SO bigint
AS
DELETE
FROM
	[GIA_THAM_DINH]
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO

if exists (select * from sysobjects where id = object_id(N'[sproc_HO_SO_THAM_DINH_GetCount]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_HO_SO_THAM_DINH_GetCount]
GO

/* Procedure sproc_HO_SO_THAM_DINH_GetCount*/
CREATE PROCEDURE sproc_HO_SO_THAM_DINH_GetCount
AS
SELECT
	COUNT(*)
FROM
	[HO_SO_THAM_DINH]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_HO_SO_THAM_DINH_Get]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_HO_SO_THAM_DINH_Get]
GO

/* Procedure sproc_HO_SO_THAM_DINH_Get*/
CREATE PROCEDURE sproc_HO_SO_THAM_DINH_Get
AS
SELECT
	--[MA_HO_SO],
	--[MA_DKS],
	--[SO_PHIEU],
	--[TEN_CHU_SU_DUNG],
	--[DIA_CHI],
	--[GPS_LATITUDE],
	--[GPS_LONGTITUDE],
	--[GPS_CHI_CHU],
	--[TINH_TRANG_PHAP_LY],
	--[NOI_DUNG_PHAP_LY],
	--[LOAI_KHU_VUC_KINH_DOANH],
	--[Y_KIEN_THAM_DINH],
	--[GIA_DAT_1],
	--[GIA_DAT_2],
	--[GIA_DAT_BINH_QUAN_1],
	--[GIA_DAT_BINH_QUAN_2],
	--[NGUOI_KHOI_TAO],
	--[NGAY_KHOI_TAO],
	--[NGAY_CAP_NHAT],
	--[ACTIVE_FLAG]

*
FROM
	[HO_SO_THAM_DINH]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_HO_SO_THAM_DINH_GetByMA_HO_SO]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_HO_SO_THAM_DINH_GetByMA_HO_SO]
GO

/* Procedure sproc_HO_SO_THAM_DINH_GetByMA_HO_SO*/
CREATE PROCEDURE sproc_HO_SO_THAM_DINH_GetByMA_HO_SO
@MA_HO_SO bigint
AS
SELECT
	--[MA_HO_SO],
	--[MA_DKS],
	--[SO_PHIEU],
	--[TEN_CHU_SU_DUNG],
	--[DIA_CHI],
	--[GPS_LATITUDE],
	--[GPS_LONGTITUDE],
	--[GPS_CHI_CHU],
	--[TINH_TRANG_PHAP_LY],
	--[NOI_DUNG_PHAP_LY],
	--[LOAI_KHU_VUC_KINH_DOANH],
	--[Y_KIEN_THAM_DINH],
	--[GIA_DAT_1],
	--[GIA_DAT_2],
	--[GIA_DAT_BINH_QUAN_1],
	--[GIA_DAT_BINH_QUAN_2],
	--[NGUOI_KHOI_TAO],
	--[NGAY_KHOI_TAO],
	--[NGAY_CAP_NHAT],
	--[ACTIVE_FLAG]

*
FROM
	[HO_SO_THAM_DINH]
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO



if exists (select * from sysobjects where id = object_id(N'[sproc_HO_SO_THAM_DINH_GetPaged]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_HO_SO_THAM_DINH_GetPaged]
GO

/* Procedure sproc_HO_SO_THAM_DINH_GetPaged*/
CREATE PROCEDURE sproc_HO_SO_THAM_DINH_GetPaged
	@RecPerPage INT,
	@PageIndex INT
AS

DECLARE @FirstRec INT
DECLARE @LastRec INT

SET @FirstRec = (@PageIndex - 1)*@RecPerPage + 1
SET @LastRec = @PageIndex *@RecPerPage 

-- create temp table to paging
CREATE TABLE #tmp_paging_index
(
	recID		INT IDENTITY(1,1) NOT NULL,
	messageID	bigint
)

-- insert temp records
INSERT INTO #tmp_paging_index(messageID)
SELECT [MA_HO_SO]
FROM [HO_SO_THAM_DINH]


-- query out
SELECT *
FROM [HO_SO_THAM_DINH]
WHERE [MA_HO_SO]
IN (
	SELECT messageID 
	FROM #tmp_paging_index 
	WHERE recID >= @FirstRec AND recID <= @LastRec
)
DROP TABLE #tmp_paging_index

GO



if exists (select * from sysobjects where id = object_id(N'[sproc_HO_SO_THAM_DINH_Add]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_HO_SO_THAM_DINH_Add]
GO

/* Procedure sproc_HO_SO_THAM_DINH_Add*/
CREATE PROCEDURE sproc_HO_SO_THAM_DINH_Add
	@MA_HO_SO bigint OUTPUT
	,@MA_DKS bigint
	,@SO_PHIEU NVARCHAR(255)
	,@TEN_CHU_SU_DUNG NVARCHAR(255)
	,@DIA_CHI NVARCHAR(255)
	,@GPS_LATITUDE float(8)
	,@GPS_LONGTITUDE float(8)
	,@GPS_CHI_CHU NVARCHAR(255)
	,@TINH_TRANG_PHAP_LY bigint
	,@NOI_DUNG_PHAP_LY NVARCHAR(255)
	,@LOAI_KHU_VUC_KINH_DOANH int
	,@Y_KIEN_THAM_DINH NVARCHAR(1023)
	,@GIA_DAT_1 float(8)
	,@GIA_DAT_2 float(8)
	,@GIA_DAT_BINH_QUAN_1 float(8)
	,@GIA_DAT_BINH_QUAN_2 float(8)
	,@NGUOI_KHOI_TAO uniqueidentifier
	,@NGAY_KHOI_TAO datetime
	,@NGAY_CAP_NHAT datetime
	,@ACTIVE_FLAG char(1)

AS

	INSERT INTO [HO_SO_THAM_DINH]
	(
		[MA_DKS],
		[SO_PHIEU],
		[TEN_CHU_SU_DUNG],
		[DIA_CHI],
		[GPS_LATITUDE],
		[GPS_LONGTITUDE],
		[GPS_CHI_CHU],
		[TINH_TRANG_PHAP_LY],
		[NOI_DUNG_PHAP_LY],
		[LOAI_KHU_VUC_KINH_DOANH],
		[Y_KIEN_THAM_DINH],
		[GIA_DAT_1],
		[GIA_DAT_2],
		[GIA_DAT_BINH_QUAN_1],
		[GIA_DAT_BINH_QUAN_2],
		[NGUOI_CAP_NHAT],
		[NGUOI_KHOI_TAO],
		[NGAY_KHOI_TAO],
		[NGAY_CAP_NHAT],
		[ACTIVE_FLAG]
	)
	VALUES
	(
		@MA_DKS,
		@SO_PHIEU,
		@TEN_CHU_SU_DUNG,
		@DIA_CHI,
		@GPS_LATITUDE,
		@GPS_LONGTITUDE,
		@GPS_CHI_CHU,
		@TINH_TRANG_PHAP_LY,
		@NOI_DUNG_PHAP_LY,
		@LOAI_KHU_VUC_KINH_DOANH,
		@Y_KIEN_THAM_DINH,
		@GIA_DAT_1,
		@GIA_DAT_2,
		@GIA_DAT_BINH_QUAN_1,
		@GIA_DAT_BINH_QUAN_2,
		@NGUOI_KHOI_TAO,
		@NGUOI_KHOI_TAO,
		@NGAY_KHOI_TAO,
		@NGAY_CAP_NHAT,
		@ACTIVE_FLAG
	)
	SELECT
		@MA_HO_SO = @@Identity

GO
if exists (select * from sysobjects where id = object_id(N'[sproc_HO_SO_THAM_DINH_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_HO_SO_THAM_DINH_Update]
GO

/* Procedure sproc_HO_SO_THAM_DINH_Update*/
CREATE PROCEDURE sproc_HO_SO_THAM_DINH_Update
	@MA_DKS bigint,
	@SO_PHIEU NVARCHAR(255),
	@TEN_CHU_SU_DUNG NVARCHAR(255),
	@DIA_CHI NVARCHAR(255),
	@GPS_LATITUDE float(8),
	@GPS_LONGTITUDE float(8),
	@GPS_CHI_CHU NVARCHAR(255),
	@TINH_TRANG_PHAP_LY bigint,
	@NOI_DUNG_PHAP_LY NVARCHAR(255),
	@LOAI_KHU_VUC_KINH_DOANH int,
	@Y_KIEN_THAM_DINH NVARCHAR(1023),
	@GIA_DAT_1 float(8),
	@GIA_DAT_2 float(8),
	@GIA_DAT_BINH_QUAN_1 float(8),
	@GIA_DAT_BINH_QUAN_2 float(8),
	@NGUOI_KHOI_TAO uniqueidentifier,
	@NGAY_KHOI_TAO datetime,
	@NGAY_CAP_NHAT datetime,
	@ACTIVE_FLAG char(1),
	@MA_HO_SO bigint

AS
UPDATE [HO_SO_THAM_DINH]
SET
	[MA_DKS] = @MA_DKS,
	[SO_PHIEU] = @SO_PHIEU,
	[TEN_CHU_SU_DUNG] = @TEN_CHU_SU_DUNG,
	[DIA_CHI] = @DIA_CHI,
	[GPS_LATITUDE] = @GPS_LATITUDE,
	[GPS_LONGTITUDE] = @GPS_LONGTITUDE,
	[GPS_CHI_CHU] = @GPS_CHI_CHU,
	[TINH_TRANG_PHAP_LY] = @TINH_TRANG_PHAP_LY,
	[NOI_DUNG_PHAP_LY] = @NOI_DUNG_PHAP_LY,
	[LOAI_KHU_VUC_KINH_DOANH] = @LOAI_KHU_VUC_KINH_DOANH,
	[Y_KIEN_THAM_DINH] = @Y_KIEN_THAM_DINH,
	[GIA_DAT_1] = @GIA_DAT_1,
	[GIA_DAT_2] = @GIA_DAT_2,
	[GIA_DAT_BINH_QUAN_1] = @GIA_DAT_BINH_QUAN_1,
	[GIA_DAT_BINH_QUAN_2] = @GIA_DAT_BINH_QUAN_2,
	[NGUOI_CAP_NHAT] = @NGUOI_KHOI_TAO,
	[NGAY_KHOI_TAO] = @NGAY_KHOI_TAO,
	[NGAY_CAP_NHAT] = @NGAY_CAP_NHAT,
	[ACTIVE_FLAG] = @ACTIVE_FLAG
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO

if exists (select * from sysobjects where id = object_id(N'[sproc_HO_SO_THAM_DINH_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_HO_SO_THAM_DINH_Delete]
GO

/* Procedure sproc_HO_SO_THAM_DINH_Delete*/
CREATE PROCEDURE sproc_HO_SO_THAM_DINH_Delete
	@MA_HO_SO bigint
AS
DELETE
FROM
	[HO_SO_THAM_DINH]
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO

if exists (select * from sysobjects where id = object_id(N'[sproc_THAM_SO_GetCount]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THAM_SO_GetCount]
GO

/* Procedure sproc_THAM_SO_GetCount*/
CREATE PROCEDURE sproc_THAM_SO_GetCount
AS
SELECT
	COUNT(*)
FROM
	[THAM_SO]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_THAM_SO_Get]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THAM_SO_Get]
GO

/* Procedure sproc_THAM_SO_Get*/
CREATE PROCEDURE sproc_THAM_SO_Get
AS
SELECT
	--[MA_THAM_SO],
	--[PARENT_ID],
	--[LOAI_THAM_SO],
	--[NOI_DUNG],
	--[SEQUENCE],
	--[GHI_CHU]

*
FROM
	[THAM_SO]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_THAM_SO_GetByMA_THAM_SO]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THAM_SO_GetByMA_THAM_SO]
GO

/* Procedure sproc_THAM_SO_GetByMA_THAM_SO*/
CREATE PROCEDURE sproc_THAM_SO_GetByMA_THAM_SO
@MA_THAM_SO bigint
AS
SELECT
	--[MA_THAM_SO],
	--[PARENT_ID],
	--[LOAI_THAM_SO],
	--[NOI_DUNG],
	--[SEQUENCE],
	--[GHI_CHU]

*
FROM
	[THAM_SO]
WHERE
	[MA_THAM_SO] = @MA_THAM_SO
GO



if exists (select * from sysobjects where id = object_id(N'[sproc_THAM_SO_GetPaged]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THAM_SO_GetPaged]
GO

/* Procedure sproc_THAM_SO_GetPaged*/
CREATE PROCEDURE sproc_THAM_SO_GetPaged
	@RecPerPage INT,
	@PageIndex INT
AS

DECLARE @FirstRec INT
DECLARE @LastRec INT

SET @FirstRec = (@PageIndex - 1)*@RecPerPage + 1
SET @LastRec = @PageIndex *@RecPerPage 

-- create temp table to paging
CREATE TABLE #tmp_paging_index
(
	recID		INT IDENTITY(1,1) NOT NULL,
	messageID	bigint
)

-- insert temp records
INSERT INTO #tmp_paging_index(messageID)
SELECT [MA_THAM_SO]
FROM [THAM_SO]


-- query out
SELECT *
FROM [THAM_SO]
WHERE [MA_THAM_SO]
IN (
	SELECT messageID 
	FROM #tmp_paging_index 
	WHERE recID >= @FirstRec AND recID <= @LastRec
)
DROP TABLE #tmp_paging_index

GO



if exists (select * from sysobjects where id = object_id(N'[sproc_THAM_SO_Add]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THAM_SO_Add]
GO

/* Procedure sproc_THAM_SO_Add*/
CREATE PROCEDURE sproc_THAM_SO_Add
	@MA_THAM_SO bigint OUTPUT
	,@PARENT_ID bigint
	,@LOAI_THAM_SO NVARCHAR(50)
	,@NOI_DUNG NVARCHAR(255)
	,@SEQUENCE int
	,@GHI_CHU NVARCHAR(50)

AS

	INSERT INTO [THAM_SO]
	(
		[PARENT_ID],
		[LOAI_THAM_SO],
		[NOI_DUNG],
		[SEQUENCE],
		[GHI_CHU]
	)
	VALUES
	(
		@PARENT_ID,
		@LOAI_THAM_SO,
		@NOI_DUNG,
		@SEQUENCE,
		@GHI_CHU
	)
	SELECT
		@MA_THAM_SO = @@Identity

GO
if exists (select * from sysobjects where id = object_id(N'[sproc_THAM_SO_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THAM_SO_Update]
GO

/* Procedure sproc_THAM_SO_Update*/
CREATE PROCEDURE sproc_THAM_SO_Update
	@PARENT_ID bigint,
	@LOAI_THAM_SO NVARCHAR(50),
	@NOI_DUNG NVARCHAR(255),
	@SEQUENCE int,
	@GHI_CHU NVARCHAR(50),
	@MA_THAM_SO bigint

AS
UPDATE [THAM_SO]
SET
	[PARENT_ID] = @PARENT_ID,
	[LOAI_THAM_SO] = @LOAI_THAM_SO,
	[NOI_DUNG] = @NOI_DUNG,
	[SEQUENCE] = @SEQUENCE,
	[GHI_CHU] = @GHI_CHU
WHERE
	[MA_THAM_SO] = @MA_THAM_SO
GO

if exists (select * from sysobjects where id = object_id(N'[sproc_THAM_SO_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THAM_SO_Delete]
GO

/* Procedure sproc_THAM_SO_Delete*/
CREATE PROCEDURE sproc_THAM_SO_Delete
	@MA_THAM_SO bigint
AS
DELETE
FROM
	[THAM_SO]
WHERE
	[MA_THAM_SO] = @MA_THAM_SO
GO

if exists (select * from sysobjects where id = object_id(N'[sproc_THONG_TIN_VI_TRI_GetCount]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THONG_TIN_VI_TRI_GetCount]
GO

/* Procedure sproc_THONG_TIN_VI_TRI_GetCount*/
CREATE PROCEDURE sproc_THONG_TIN_VI_TRI_GetCount
AS
SELECT
	COUNT(*)
FROM
	[THONG_TIN_VI_TRI]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_THONG_TIN_VI_TRI_Get]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THONG_TIN_VI_TRI_Get]
GO

/* Procedure sproc_THONG_TIN_VI_TRI_Get*/
CREATE PROCEDURE sproc_THONG_TIN_VI_TRI_Get
AS
SELECT
	--[MA_HO_SO],
	--[CACH_TRUNG_TAM],
	--[CACH_DUONG_CHINH]

*
FROM
	[THONG_TIN_VI_TRI]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_THONG_TIN_VI_TRI_GetByMA_HO_SO]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THONG_TIN_VI_TRI_GetByMA_HO_SO]
GO

/* Procedure sproc_THONG_TIN_VI_TRI_GetByMA_HO_SO*/
CREATE PROCEDURE sproc_THONG_TIN_VI_TRI_GetByMA_HO_SO
@MA_HO_SO bigint
AS
SELECT
	--[MA_HO_SO],
	--[CACH_TRUNG_TAM],
	--[CACH_DUONG_CHINH]

*
FROM
	[THONG_TIN_VI_TRI]
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO



if exists (select * from sysobjects where id = object_id(N'[sproc_THONG_TIN_VI_TRI_GetPaged]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THONG_TIN_VI_TRI_GetPaged]
GO

/* Procedure sproc_THONG_TIN_VI_TRI_GetPaged*/
CREATE PROCEDURE sproc_THONG_TIN_VI_TRI_GetPaged
	@RecPerPage INT,
	@PageIndex INT
AS

DECLARE @FirstRec INT
DECLARE @LastRec INT

SET @FirstRec = (@PageIndex - 1)*@RecPerPage + 1
SET @LastRec = @PageIndex *@RecPerPage 

-- create temp table to paging
CREATE TABLE #tmp_paging_index
(
	recID		INT IDENTITY(1,1) NOT NULL,
	messageID	bigint
)

-- insert temp records
INSERT INTO #tmp_paging_index(messageID)
SELECT [MA_HO_SO]
FROM [THONG_TIN_VI_TRI]


-- query out
SELECT *
FROM [THONG_TIN_VI_TRI]
WHERE [MA_HO_SO]
IN (
	SELECT messageID 
	FROM #tmp_paging_index 
	WHERE recID >= @FirstRec AND recID <= @LastRec
)
DROP TABLE #tmp_paging_index

GO



if exists (select * from sysobjects where id = object_id(N'[sproc_THONG_TIN_VI_TRI_Add]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THONG_TIN_VI_TRI_Add]
GO

/* Procedure sproc_THONG_TIN_VI_TRI_Add*/
CREATE PROCEDURE sproc_THONG_TIN_VI_TRI_Add
	@MA_HO_SO bigint
	,@CACH_TRUNG_TAM float(8)
	,@CACH_DUONG_CHINH float(8)

AS

	INSERT INTO [THONG_TIN_VI_TRI]
	(
		[MA_HO_SO],
		[CACH_TRUNG_TAM],
		[CACH_DUONG_CHINH]
	)
	VALUES
	(
		@MA_HO_SO,
		@CACH_TRUNG_TAM,
		@CACH_DUONG_CHINH
	)
GO
if exists (select * from sysobjects where id = object_id(N'[sproc_THONG_TIN_VI_TRI_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THONG_TIN_VI_TRI_Update]
GO

/* Procedure sproc_THONG_TIN_VI_TRI_Update*/
CREATE PROCEDURE sproc_THONG_TIN_VI_TRI_Update
	@CACH_TRUNG_TAM float(8),
	@CACH_DUONG_CHINH float(8),
	@MA_HO_SO bigint

AS
UPDATE [THONG_TIN_VI_TRI]
SET
	[CACH_TRUNG_TAM] = @CACH_TRUNG_TAM,
	[CACH_DUONG_CHINH] = @CACH_DUONG_CHINH
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO

if exists (select * from sysobjects where id = object_id(N'[sproc_THONG_TIN_VI_TRI_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THONG_TIN_VI_TRI_Delete]
GO

/* Procedure sproc_THONG_TIN_VI_TRI_Delete*/
CREATE PROCEDURE sproc_THONG_TIN_VI_TRI_Delete
	@MA_HO_SO bigint
AS
DELETE
FROM
	[THONG_TIN_VI_TRI]
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO

if exists (select * from sysobjects where id = object_id(N'[sproc_THUA_DAT_GetCount]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THUA_DAT_GetCount]
GO

/* Procedure sproc_THUA_DAT_GetCount*/
CREATE PROCEDURE sproc_THUA_DAT_GetCount
AS
SELECT
	COUNT(*)
FROM
	[THUA_DAT]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_THUA_DAT_Get]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THUA_DAT_Get]
GO

/* Procedure sproc_THUA_DAT_Get*/
CREATE PROCEDURE sproc_THUA_DAT_Get
AS
SELECT
	--[MA_HO_SO],
	--[SO_THUA_DAT],
	--[TO_BAN_DO],
	--[CHIEU_DAI],
	--[CHIEU_RONG],
	--[TONG_DIEN_TICH],
	--[DIEN_TICH_CONG_NHAN],
	--[DIEN_TICH_KHONG_CONG_NHAN],
	--[DIEN_TICH_SU_DUNG_CHUNG],
	--[LOAI_HINH_DANG_THUA_DAT],
	--[HINH_DANG_THUA_DAT],
	--[LOAI_DUONG_PHO],
	--[LO_GIOI],
	--[SO_MAT_TIEN],
	--[LOAI_LAN_DUONG],
	--[NOI_DUNG_LAN_DUONG],
	--[LOAI_HEM]

*
FROM
	[THUA_DAT]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_THUA_DAT_GetByMA_HO_SO]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THUA_DAT_GetByMA_HO_SO]
GO

/* Procedure sproc_THUA_DAT_GetByMA_HO_SO*/
CREATE PROCEDURE sproc_THUA_DAT_GetByMA_HO_SO
@MA_HO_SO bigint
AS
SELECT
	--[MA_HO_SO],
	--[SO_THUA_DAT],
	--[TO_BAN_DO],
	--[CHIEU_DAI],
	--[CHIEU_RONG],
	--[TONG_DIEN_TICH],
	--[DIEN_TICH_CONG_NHAN],
	--[DIEN_TICH_KHONG_CONG_NHAN],
	--[DIEN_TICH_SU_DUNG_CHUNG],
	--[LOAI_HINH_DANG_THUA_DAT],
	--[HINH_DANG_THUA_DAT],
	--[LOAI_DUONG_PHO],
	--[LO_GIOI],
	--[SO_MAT_TIEN],
	--[LOAI_LAN_DUONG],
	--[NOI_DUNG_LAN_DUONG],
	--[LOAI_HEM]

*
FROM
	[THUA_DAT]
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO



if exists (select * from sysobjects where id = object_id(N'[sproc_THUA_DAT_GetPaged]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THUA_DAT_GetPaged]
GO

/* Procedure sproc_THUA_DAT_GetPaged*/
CREATE PROCEDURE sproc_THUA_DAT_GetPaged
	@RecPerPage INT,
	@PageIndex INT
AS

DECLARE @FirstRec INT
DECLARE @LastRec INT

SET @FirstRec = (@PageIndex - 1)*@RecPerPage + 1
SET @LastRec = @PageIndex *@RecPerPage 

-- create temp table to paging
CREATE TABLE #tmp_paging_index
(
	recID		INT IDENTITY(1,1) NOT NULL,
	messageID	bigint
)

-- insert temp records
INSERT INTO #tmp_paging_index(messageID)
SELECT [MA_HO_SO]
FROM [THUA_DAT]


-- query out
SELECT *
FROM [THUA_DAT]
WHERE [MA_HO_SO]
IN (
	SELECT messageID 
	FROM #tmp_paging_index 
	WHERE recID >= @FirstRec AND recID <= @LastRec
)
DROP TABLE #tmp_paging_index

GO



if exists (select * from sysobjects where id = object_id(N'[sproc_THUA_DAT_Add]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THUA_DAT_Add]
GO

/* Procedure sproc_THUA_DAT_Add*/
CREATE PROCEDURE sproc_THUA_DAT_Add
	@MA_HO_SO bigint
	,@SO_THUA_DAT NVARCHAR(50)
	,@TO_BAN_DO NVARCHAR(50)
	,@CHIEU_DAI float(8)
	,@CHIEU_RONG float(8)
	,@TONG_DIEN_TICH float(8)
	,@DIEN_TICH_CONG_NHAN float(8)
	,@DIEN_TICH_KHONG_CONG_NHAN float(8)
	,@DIEN_TICH_SU_DUNG_CHUNG float(8)
	,@LOAI_HINH_DANG_THUA_DAT bigint
	,@HINH_DANG_THUA_DAT NVARCHAR(50)
	,@LOAI_DUONG_PHO bigint
	,@LO_GIOI float(8)
	,@SO_MAT_TIEN NVARCHAR(50)
	,@LOAI_LAN_DUONG bigint
	,@NOI_DUNG_LAN_DUONG NVARCHAR(50)
	,@LOAI_HEM bigint

AS

	INSERT INTO [THUA_DAT]
	(
		[MA_HO_SO],
		[SO_THUA_DAT],
		[TO_BAN_DO],
		[CHIEU_DAI],
		[CHIEU_RONG],
		[TONG_DIEN_TICH],
		[DIEN_TICH_CONG_NHAN],
		[DIEN_TICH_KHONG_CONG_NHAN],
		[DIEN_TICH_SU_DUNG_CHUNG],
		[LOAI_HINH_DANG_THUA_DAT],
		[HINH_DANG_THUA_DAT],
		[LOAI_DUONG_PHO],
		[LO_GIOI],
		[SO_MAT_TIEN],
		[LOAI_LAN_DUONG],
		[NOI_DUNG_LAN_DUONG],
		[LOAI_HEM]
	)
	VALUES
	(
		@MA_HO_SO,
		@SO_THUA_DAT,
		@TO_BAN_DO,
		@CHIEU_DAI,
		@CHIEU_RONG,
		@TONG_DIEN_TICH,
		@DIEN_TICH_CONG_NHAN,
		@DIEN_TICH_KHONG_CONG_NHAN,
		@DIEN_TICH_SU_DUNG_CHUNG,
		@LOAI_HINH_DANG_THUA_DAT,
		@HINH_DANG_THUA_DAT,
		@LOAI_DUONG_PHO,
		@LO_GIOI,
		@SO_MAT_TIEN,
		@LOAI_LAN_DUONG,
		@NOI_DUNG_LAN_DUONG,
		@LOAI_HEM
	)
GO
if exists (select * from sysobjects where id = object_id(N'[sproc_THUA_DAT_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THUA_DAT_Update]
GO

/* Procedure sproc_THUA_DAT_Update*/
CREATE PROCEDURE sproc_THUA_DAT_Update
	@SO_THUA_DAT NVARCHAR(50),
	@TO_BAN_DO NVARCHAR(50),
	@CHIEU_DAI float(8),
	@CHIEU_RONG float(8),
	@TONG_DIEN_TICH float(8),
	@DIEN_TICH_CONG_NHAN float(8),
	@DIEN_TICH_KHONG_CONG_NHAN float(8),
	@DIEN_TICH_SU_DUNG_CHUNG float(8),
	@LOAI_HINH_DANG_THUA_DAT bigint,
	@HINH_DANG_THUA_DAT NVARCHAR(50),
	@LOAI_DUONG_PHO bigint,
	@LO_GIOI float(8),
	@SO_MAT_TIEN NVARCHAR(50),
	@LOAI_LAN_DUONG bigint,
	@NOI_DUNG_LAN_DUONG NVARCHAR(50),
	@LOAI_HEM bigint,
	@MA_HO_SO bigint

AS
UPDATE [THUA_DAT]
SET
	[SO_THUA_DAT] = @SO_THUA_DAT,
	[TO_BAN_DO] = @TO_BAN_DO,
	[CHIEU_DAI] = @CHIEU_DAI,
	[CHIEU_RONG] = @CHIEU_RONG,
	[TONG_DIEN_TICH] = @TONG_DIEN_TICH,
	[DIEN_TICH_CONG_NHAN] = @DIEN_TICH_CONG_NHAN,
	[DIEN_TICH_KHONG_CONG_NHAN] = @DIEN_TICH_KHONG_CONG_NHAN,
	[DIEN_TICH_SU_DUNG_CHUNG] = @DIEN_TICH_SU_DUNG_CHUNG,
	[LOAI_HINH_DANG_THUA_DAT] = @LOAI_HINH_DANG_THUA_DAT,
	[HINH_DANG_THUA_DAT] = @HINH_DANG_THUA_DAT,
	[LOAI_DUONG_PHO] = @LOAI_DUONG_PHO,
	[LO_GIOI] = @LO_GIOI,
	[SO_MAT_TIEN] = @SO_MAT_TIEN,
	[LOAI_LAN_DUONG] = @LOAI_LAN_DUONG,
	[NOI_DUNG_LAN_DUONG] = @NOI_DUNG_LAN_DUONG,
	[LOAI_HEM] = @LOAI_HEM
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO

if exists (select * from sysobjects where id = object_id(N'[sproc_THUA_DAT_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_THUA_DAT_Delete]
GO

/* Procedure sproc_THUA_DAT_Delete*/
CREATE PROCEDURE sproc_THUA_DAT_Delete
	@MA_HO_SO bigint
AS
DELETE
FROM
	[THUA_DAT]
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO

if exists (select * from sysobjects where id = object_id(N'[sproc_VAT_LIEU_XAY_DUNG_GetCount]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_VAT_LIEU_XAY_DUNG_GetCount]
GO

/* Procedure sproc_VAT_LIEU_XAY_DUNG_GetCount*/
CREATE PROCEDURE sproc_VAT_LIEU_XAY_DUNG_GetCount
AS
SELECT
	COUNT(*)
FROM
	[VAT_LIEU_XAY_DUNG]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_VAT_LIEU_XAY_DUNG_Get]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_VAT_LIEU_XAY_DUNG_Get]
GO

/* Procedure sproc_VAT_LIEU_XAY_DUNG_Get*/
CREATE PROCEDURE sproc_VAT_LIEU_XAY_DUNG_Get
AS
SELECT
	--[MA_HO_SO],
	--[LOAI_KET_CAU_KHUNG],
	--[NOI_DUNG_KET_CAU_KHUNG],
	--[LOAI_KET_CAU_MONG],
	--[NOI_DUNG_KET_CAU_MONG],
	--[LOAI_KET_CAU_TUONG_NHA],
	--[NOI_DUNG_KET_CAU_TUONG_NHA],
	--[LOAI_KET_CAU_NEN],
	--[NOI_DUNG_KET_CAU_NEN],
	--[LOAI_KET_CAU_MAI],
	--[NOI_DUNG_KET_CAU_MAI],
	--[CHAT_LUONG_MONG],
	--[CHAT_LUONG_SAN],
	--[CHAT_LUONG_TUONG],
	--[CHAT_LUONG_TRAN],
	--[CHAT_LUONG_MAI],
	--[TI_LE_KET_CAU_MONG],
	--[TI_LE_KET_CAU_SAN],
	--[TI_LE_KET_CAU_TUONG],
	--[TI_LE_KET_CAU_TRAN],
	--[TI_LE_KET_CAU_MAI],
	--[SO_PHONG_NGU],
	--[SO_NHA_VE_SINH],
	--[LOAI_TRANG_TRI_NOI_THAT],
	--[NOI_DUNG_TRANG_TRI_NOI_THAT],
	--[LOAI_CONG_TRINH_XAY_DUNG],
	--[NOI_DUNG_CONG_TRINH_XAY_DUNG]

*
FROM
	[VAT_LIEU_XAY_DUNG]
GO


if exists (select * from sysobjects where id = object_id(N'[sproc_VAT_LIEU_XAY_DUNG_GetByMA_HO_SO]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_VAT_LIEU_XAY_DUNG_GetByMA_HO_SO]
GO

/* Procedure sproc_VAT_LIEU_XAY_DUNG_GetByMA_HO_SO*/
CREATE PROCEDURE sproc_VAT_LIEU_XAY_DUNG_GetByMA_HO_SO
@MA_HO_SO bigint
AS
SELECT
	--[MA_HO_SO],
	--[LOAI_KET_CAU_KHUNG],
	--[NOI_DUNG_KET_CAU_KHUNG],
	--[LOAI_KET_CAU_MONG],
	--[NOI_DUNG_KET_CAU_MONG],
	--[LOAI_KET_CAU_TUONG_NHA],
	--[NOI_DUNG_KET_CAU_TUONG_NHA],
	--[LOAI_KET_CAU_NEN],
	--[NOI_DUNG_KET_CAU_NEN],
	--[LOAI_KET_CAU_MAI],
	--[NOI_DUNG_KET_CAU_MAI],
	--[CHAT_LUONG_MONG],
	--[CHAT_LUONG_SAN],
	--[CHAT_LUONG_TUONG],
	--[CHAT_LUONG_TRAN],
	--[CHAT_LUONG_MAI],
	--[TI_LE_KET_CAU_MONG],
	--[TI_LE_KET_CAU_SAN],
	--[TI_LE_KET_CAU_TUONG],
	--[TI_LE_KET_CAU_TRAN],
	--[TI_LE_KET_CAU_MAI],
	--[SO_PHONG_NGU],
	--[SO_NHA_VE_SINH],
	--[LOAI_TRANG_TRI_NOI_THAT],
	--[NOI_DUNG_TRANG_TRI_NOI_THAT],
	--[LOAI_CONG_TRINH_XAY_DUNG],
	--[NOI_DUNG_CONG_TRINH_XAY_DUNG]

*
FROM
	[VAT_LIEU_XAY_DUNG]
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO



if exists (select * from sysobjects where id = object_id(N'[sproc_VAT_LIEU_XAY_DUNG_GetPaged]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_VAT_LIEU_XAY_DUNG_GetPaged]
GO

/* Procedure sproc_VAT_LIEU_XAY_DUNG_GetPaged*/
CREATE PROCEDURE sproc_VAT_LIEU_XAY_DUNG_GetPaged
	@RecPerPage INT,
	@PageIndex INT
AS

DECLARE @FirstRec INT
DECLARE @LastRec INT

SET @FirstRec = (@PageIndex - 1)*@RecPerPage + 1
SET @LastRec = @PageIndex *@RecPerPage 

-- create temp table to paging
CREATE TABLE #tmp_paging_index
(
	recID		INT IDENTITY(1,1) NOT NULL,
	messageID	bigint
)

-- insert temp records
INSERT INTO #tmp_paging_index(messageID)
SELECT [MA_HO_SO]
FROM [VAT_LIEU_XAY_DUNG]


-- query out
SELECT *
FROM [VAT_LIEU_XAY_DUNG]
WHERE [MA_HO_SO]
IN (
	SELECT messageID 
	FROM #tmp_paging_index 
	WHERE recID >= @FirstRec AND recID <= @LastRec
)
DROP TABLE #tmp_paging_index

GO



if exists (select * from sysobjects where id = object_id(N'[sproc_VAT_LIEU_XAY_DUNG_Add]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_VAT_LIEU_XAY_DUNG_Add]
GO

/* Procedure sproc_VAT_LIEU_XAY_DUNG_Add*/
CREATE PROCEDURE sproc_VAT_LIEU_XAY_DUNG_Add
	@MA_HO_SO bigint
	,@LOAI_KET_CAU_KHUNG bigint
	,@NOI_DUNG_KET_CAU_KHUNG NVARCHAR(50)
	,@LOAI_KET_CAU_MONG bigint
	,@NOI_DUNG_KET_CAU_MONG NVARCHAR(50)
	,@LOAI_KET_CAU_TUONG_NHA bigint
	,@NOI_DUNG_KET_CAU_TUONG_NHA NVARCHAR(50)
	,@LOAI_KET_CAU_NEN bigint
	,@NOI_DUNG_KET_CAU_NEN NVARCHAR(50)
	,@LOAI_KET_CAU_MAI bigint
	,@NOI_DUNG_KET_CAU_MAI NVARCHAR(50)
	,@CHAT_LUONG_MONG float(8)
	,@CHAT_LUONG_SAN float(8)
	,@CHAT_LUONG_TUONG float(8)
	,@CHAT_LUONG_TRAN float(8)
	,@CHAT_LUONG_MAI float(8)
	,@TI_LE_KET_CAU_MONG float(8)
	,@TI_LE_KET_CAU_SAN float(8)
	,@TI_LE_KET_CAU_TUONG float(8)
	,@TI_LE_KET_CAU_TRAN float(8)
	,@TI_LE_KET_CAU_MAI float(8)
	,@SO_PHONG_NGU int
	,@SO_NHA_VE_SINH int
	,@LOAI_TRANG_TRI_NOI_THAT bigint
	,@NOI_DUNG_TRANG_TRI_NOI_THAT NVARCHAR(50)
	,@LOAI_CONG_TRINH_XAY_DUNG bigint
	,@NOI_DUNG_CONG_TRINH_XAY_DUNG NVARCHAR(50)

AS

	INSERT INTO [VAT_LIEU_XAY_DUNG]
	(
		[MA_HO_SO],
		[LOAI_KET_CAU_KHUNG],
		[NOI_DUNG_KET_CAU_KHUNG],
		[LOAI_KET_CAU_MONG],
		[NOI_DUNG_KET_CAU_MONG],
		[LOAI_KET_CAU_TUONG_NHA],
		[NOI_DUNG_KET_CAU_TUONG_NHA],
		[LOAI_KET_CAU_NEN],
		[NOI_DUNG_KET_CAU_NEN],
		[LOAI_KET_CAU_MAI],
		[NOI_DUNG_KET_CAU_MAI],
		[CHAT_LUONG_MONG],
		[CHAT_LUONG_SAN],
		[CHAT_LUONG_TUONG],
		[CHAT_LUONG_TRAN],
		[CHAT_LUONG_MAI],
		[TI_LE_KET_CAU_MONG],
		[TI_LE_KET_CAU_SAN],
		[TI_LE_KET_CAU_TUONG],
		[TI_LE_KET_CAU_TRAN],
		[TI_LE_KET_CAU_MAI],
		[SO_PHONG_NGU],
		[SO_NHA_VE_SINH],
		[LOAI_TRANG_TRI_NOI_THAT],
		[NOI_DUNG_TRANG_TRI_NOI_THAT],
		[LOAI_CONG_TRINH_XAY_DUNG],
		[NOI_DUNG_CONG_TRINH_XAY_DUNG]
	)
	VALUES
	(
		@MA_HO_SO,
		@LOAI_KET_CAU_KHUNG,
		@NOI_DUNG_KET_CAU_KHUNG,
		@LOAI_KET_CAU_MONG,
		@NOI_DUNG_KET_CAU_MONG,
		@LOAI_KET_CAU_TUONG_NHA,
		@NOI_DUNG_KET_CAU_TUONG_NHA,
		@LOAI_KET_CAU_NEN,
		@NOI_DUNG_KET_CAU_NEN,
		@LOAI_KET_CAU_MAI,
		@NOI_DUNG_KET_CAU_MAI,
		@CHAT_LUONG_MONG,
		@CHAT_LUONG_SAN,
		@CHAT_LUONG_TUONG,
		@CHAT_LUONG_TRAN,
		@CHAT_LUONG_MAI,
		@TI_LE_KET_CAU_MONG,
		@TI_LE_KET_CAU_SAN,
		@TI_LE_KET_CAU_TUONG,
		@TI_LE_KET_CAU_TRAN,
		@TI_LE_KET_CAU_MAI,
		@SO_PHONG_NGU,
		@SO_NHA_VE_SINH,
		@LOAI_TRANG_TRI_NOI_THAT,
		@NOI_DUNG_TRANG_TRI_NOI_THAT,
		@LOAI_CONG_TRINH_XAY_DUNG,
		@NOI_DUNG_CONG_TRINH_XAY_DUNG
	)
GO
if exists (select * from sysobjects where id = object_id(N'[sproc_VAT_LIEU_XAY_DUNG_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_VAT_LIEU_XAY_DUNG_Update]
GO

/* Procedure sproc_VAT_LIEU_XAY_DUNG_Update*/
CREATE PROCEDURE sproc_VAT_LIEU_XAY_DUNG_Update
	@LOAI_KET_CAU_KHUNG bigint,
	@NOI_DUNG_KET_CAU_KHUNG NVARCHAR(50),
	@LOAI_KET_CAU_MONG bigint,
	@NOI_DUNG_KET_CAU_MONG NVARCHAR(50),
	@LOAI_KET_CAU_TUONG_NHA bigint,
	@NOI_DUNG_KET_CAU_TUONG_NHA NVARCHAR(50),
	@LOAI_KET_CAU_NEN bigint,
	@NOI_DUNG_KET_CAU_NEN NVARCHAR(50),
	@LOAI_KET_CAU_MAI bigint,
	@NOI_DUNG_KET_CAU_MAI NVARCHAR(50),
	@CHAT_LUONG_MONG float(8),
	@CHAT_LUONG_SAN float(8),
	@CHAT_LUONG_TUONG float(8),
	@CHAT_LUONG_TRAN float(8),
	@CHAT_LUONG_MAI float(8),
	@TI_LE_KET_CAU_MONG float(8),
	@TI_LE_KET_CAU_SAN float(8),
	@TI_LE_KET_CAU_TUONG float(8),
	@TI_LE_KET_CAU_TRAN float(8),
	@TI_LE_KET_CAU_MAI float(8),
	@SO_PHONG_NGU int,
	@SO_NHA_VE_SINH int,
	@LOAI_TRANG_TRI_NOI_THAT bigint,
	@NOI_DUNG_TRANG_TRI_NOI_THAT NVARCHAR(50),
	@LOAI_CONG_TRINH_XAY_DUNG bigint,
	@NOI_DUNG_CONG_TRINH_XAY_DUNG NVARCHAR(50),
	@MA_HO_SO bigint

AS
UPDATE [VAT_LIEU_XAY_DUNG]
SET
	[LOAI_KET_CAU_KHUNG] = @LOAI_KET_CAU_KHUNG,
	[NOI_DUNG_KET_CAU_KHUNG] = @NOI_DUNG_KET_CAU_KHUNG,
	[LOAI_KET_CAU_MONG] = @LOAI_KET_CAU_MONG,
	[NOI_DUNG_KET_CAU_MONG] = @NOI_DUNG_KET_CAU_MONG,
	[LOAI_KET_CAU_TUONG_NHA] = @LOAI_KET_CAU_TUONG_NHA,
	[NOI_DUNG_KET_CAU_TUONG_NHA] = @NOI_DUNG_KET_CAU_TUONG_NHA,
	[LOAI_KET_CAU_NEN] = @LOAI_KET_CAU_NEN,
	[NOI_DUNG_KET_CAU_NEN] = @NOI_DUNG_KET_CAU_NEN,
	[LOAI_KET_CAU_MAI] = @LOAI_KET_CAU_MAI,
	[NOI_DUNG_KET_CAU_MAI] = @NOI_DUNG_KET_CAU_MAI,
	[CHAT_LUONG_MONG] = @CHAT_LUONG_MONG,
	[CHAT_LUONG_SAN] = @CHAT_LUONG_SAN,
	[CHAT_LUONG_TUONG] = @CHAT_LUONG_TUONG,
	[CHAT_LUONG_TRAN] = @CHAT_LUONG_TRAN,
	[CHAT_LUONG_MAI] = @CHAT_LUONG_MAI,
	[TI_LE_KET_CAU_MONG] = @TI_LE_KET_CAU_MONG,
	[TI_LE_KET_CAU_SAN] = @TI_LE_KET_CAU_SAN,
	[TI_LE_KET_CAU_TUONG] = @TI_LE_KET_CAU_TUONG,
	[TI_LE_KET_CAU_TRAN] = @TI_LE_KET_CAU_TRAN,
	[TI_LE_KET_CAU_MAI] = @TI_LE_KET_CAU_MAI,
	[SO_PHONG_NGU] = @SO_PHONG_NGU,
	[SO_NHA_VE_SINH] = @SO_NHA_VE_SINH,
	[LOAI_TRANG_TRI_NOI_THAT] = @LOAI_TRANG_TRI_NOI_THAT,
	[NOI_DUNG_TRANG_TRI_NOI_THAT] = @NOI_DUNG_TRANG_TRI_NOI_THAT,
	[LOAI_CONG_TRINH_XAY_DUNG] = @LOAI_CONG_TRINH_XAY_DUNG,
	[NOI_DUNG_CONG_TRINH_XAY_DUNG] = @NOI_DUNG_CONG_TRINH_XAY_DUNG
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO

if exists (select * from sysobjects where id = object_id(N'[sproc_VAT_LIEU_XAY_DUNG_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure [sproc_VAT_LIEU_XAY_DUNG_Delete]
GO

/* Procedure sproc_VAT_LIEU_XAY_DUNG_Delete*/
CREATE PROCEDURE sproc_VAT_LIEU_XAY_DUNG_Delete
	@MA_HO_SO bigint
AS
DELETE
FROM
	[VAT_LIEU_XAY_DUNG]
WHERE
	[MA_HO_SO] = @MA_HO_SO
GO


